package com.example.sale.serviceImpl;

import com.example.sale.dao.SaleDAO;
import com.example.sale.entity.SaleChance;
import com.example.sale.service.SaleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service("SaleServiceImpl")
public class SaleServiceImpl implements SaleService {

    @Autowired
    SaleDAO saleDAO;

    @Override
    public List<SaleChance> queryDataAll() {
        List<SaleChance> list = saleDAO.queryDataAll();
       return list;
    }

    @Override
    public SaleChance queryChanceById(String id) {
        SaleChance data = saleDAO.queryChanceById(id);
        return data;
    }

    @Override
    public PageInfo<SaleChance> queryData(SaleChance saleChance, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum,pageSize);
        List<SaleChance> data = saleDAO.queryData(saleChance);
        PageInfo<SaleChance> dataList  =  new PageInfo<>(data);
        return dataList;
    }

    @Override
    @Transactional     //-->出错则事务回滚，不会添加到数据库(不会处理请求)
    public void deleteInfo(String id) {
        saleDAO.deleteInfo(id);
    }

    @Override
    @Transactional     //-->出错则事务回滚，不会添加到数据库(不会处理请求)
    public void updateInfo(SaleChance saleChance) {
        saleDAO.updateInfo(saleChance);
    }

    @Override
    @Transactional     //-->出错则事务回滚，不会添加到数据库(不会处理请求)
    public void saveInfo(SaleChance saleChance, HttpServletRequest request) {
        saleDAO.saveInfo(saleChance,request);
    }
}





